package org.wmq.javafxmapcollectionstandalone;

import org.wmq.javafxmapcollectionstandalone.mapper.impl.MapEntityMapperImplByFileSystem;
import org.wmq.javafxmapcollectionstandalone.model.Entity.MapEntity;
import org.wmq.javafxmapcollectionstandalone.model.common.MyList;
import org.wmq.javafxmapcollectionstandalone.service.CommentService;
import org.wmq.javafxmapcollectionstandalone.service.MapEntityService;
import org.wmq.javafxmapcollectionstandalone.service.impl.CommentServiceImpl;
import org.wmq.javafxmapcollectionstandalone.service.impl.MapEntityServiceImpl;

import java.io.File;

public class God {
    private God(){
        String filePrefix = MapEntityMapperImplByFileSystem.FILE_PREFIX;
        for (String filename : new File(filePrefix).list()) {
            Long id = Long.parseLong(filename.substring(0, filename.lastIndexOf(".")));
            this.mapEntityList.add(mapEntityService.getById(id));
        }
    }

    private static final God god = new God();
    public static final God getGod(){
        return god;
    }

    private MyList<MapEntity> mapEntityList = new MyList<>();
    private MapEntityService mapEntityService = new MapEntityServiceImpl();
    private CommentService commentService = new CommentServiceImpl();

    public MyList<MapEntity> getMapEntityList(){
        return this.mapEntityList;
    }

    public MapEntityService getMapEntityService(){
        return this.mapEntityService;
    }

    public CommentService getCommentService(){
        return this.commentService;
    }
}
